//
//  Contact.m
//  cliqset
//
//  Created by David Hinson on 2/10/09.
//  Copyright 2009 Sumner Systems Management, Inc.. All rights reserved.
//

#import "Contact.h"

// Contacts
@implementation Contact

@synthesize contactIdentifier = _contactIdentifier;
@synthesize givenName         = _givenName;
@synthesize middleName        = _middleName;
@synthesize familyName        = _familyName;
@synthesize notes             = _notes;
@synthesize company           = _company;
@synthesize position          = _position;
@synthesize photoURL          = _photoURL;
@synthesize photoBlob         = _photoBlob;
@synthesize lastUpdate        = _lastUpdate;

@synthesize tags              = _tags;
@synthesize emailAddresses    = _emailAddresses;
@synthesize addresses         = _addresses;
@synthesize imScreenNames     = _imScreenNames;
@synthesize phones            = _phones;
@synthesize urls              = _urls;

// Prep our arrays for first time use
-(id)init {
	self = [super init];
	
	_addresses      = [[NSMutableArray alloc] init];
	_emailAddresses = [[NSMutableArray alloc] init];
	_imScreenNames  = [[NSMutableArray alloc] init];
	_phones         = [[NSMutableArray alloc] init];
	_tags           = [[NSMutableArray alloc] init];
	_urls           = [[NSMutableArray alloc] init];
	
	return self;
}

-(NSString*)description {
	NSMutableString * desc = (NSMutableString*)[@"" stringByAppendingFormat:@"\r\n_______\r\nContact\r\n_______\r\n"];

	desc = (NSMutableString*)[desc stringByAppendingFormat:@"%@ %@\r\n_______", self.givenName, self.familyName];
	return desc;
}

// Free up our junk
- (void)dealloc {

	// NSLog(@"%@ dealloc", [self description]);
	
	[_contactIdentifier release];
	[_givenName release];
	[_middleName release];
	[_familyName release];
	[_notes release];
	[_company release];
	[_position release];
	[_photoURL release];
	[_photoBlob release];
	[_lastUpdate release];
	
	[_addresses removeAllObjects];
	[_emailAddresses removeAllObjects];
	[_imScreenNames removeAllObjects];
	[_phones removeAllObjects];
	[_urls removeAllObjects];
	[_tags removeAllObjects];
	
	[_tags release];
	[_emailAddresses release];
	[_addresses release];
	[_imScreenNames release];
	[_phones release];
	[_urls release];
	
    [super dealloc];
}

@end

// Tags
@implementation Tag

@synthesize tag = _tag;

-(id)init {
	self = [super init];
	return self;
}

- (void)dealloc {
	//NSLog(@"%@ dealloc", [self description]);
	[_tag release];
	[super dealloc];
}

@end

// Email addresses
@implementation EmailAddress

@synthesize type    = _type;
@synthesize address = _address;
@synthesize primary = _primary;

-(id)init {
	self = [super init];
	return self;
}

- (void)dealloc {
	//NSLog(@"%@ dealloc", [self description]);
	[_type release];
	[_address release];
	[super dealloc];
}

@end

// IMs
@implementation IM

@synthesize network = _network;
@synthesize name    = _name;
@synthesize primary = _primary;

-(id)init {
	self = [super init];
	return self;
}	

- (void)dealloc {
	//NSLog(@"%@ dealloc", [self description]);
	[_network release];
	[_name release];
	[super dealloc];
}

@end

// Phones
@implementation Phone

@synthesize type        = _type;
@synthesize phoneNumber = _phoneNumber;
@synthesize primary     = _primary;

-(id)init {
	self = [super init];
	return self;
}

- (void)dealloc {
	//NSLog(@"%@ dealloc", [self description]);
	[_type release];
	[_phoneNumber release];
	[super dealloc];
}

@end

// Addresses
@implementation Address

@synthesize type          = _type;
@synthesize primary       = _primary;
@synthesize streetAddress = _streetAddress;
@synthesize locality      = _locality;
@synthesize region        = _region;
@synthesize country       = _country;
@synthesize postalCode    = _postalCode;

-(id)init {
	self = [super init];
	return self;
}

- (void)dealloc {
	//NSLog(@"%@ dealloc", [self description]);
	[_type release];
	[_streetAddress release];
	[_locality release];
	[_region release];
	[_country release];
	[_postalCode release];
	[super dealloc];
}

@end

// URLs
@implementation URL

@synthesize type    = _type;
@synthesize url     = _url;
@synthesize primary = _primary;

-(id)init {
	self = [super init];
	return self;
}

- (void)dealloc {
	//NSLog(@"%@ dealloc", [self description]);
	[_type release];
	[_url release];
	[super dealloc];
}
	
@end


